package com.hsteach.enums;

import com.hsteach.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum VisitConditionEnum {

    INTEREST(1, "重点学生"),
    HAS_PEERS(2, "有同行人"),
    HAS_SAFE_EVENT(3, "安全事件"),
    NO_CONDITION(-1, "无条件"),
    ;
    private Integer code;
    private String name;

    public static VisitConditionEnum getByCode(Integer code) {
        VisitConditionEnum visitConditionEnum = Arrays.stream(VisitConditionEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        if (visitConditionEnum == null) {
            throw new ServiceException("不存在的查询条件");
        }
        return visitConditionEnum;
    }
}
